How to find the the inverse of a permutation